import request from '../utils/request'

interface ChatApi {
  getMessages: (params: {
    contextType?: string
    contextId: string
    page?: number
    pageSize?: number
  }) => Promise<any>
  
  sendMessage: (data: {
    contextType?: string
    contextId: string
    receiverId: string
    content: string
    messageType?: string
  }) => Promise<any>
  
  markAsRead: (messageId: string) => Promise<any>
  
  markAllAsRead: (data: {
    contextType?: string
    contextId: string
  }) => Promise<any>
  
  getUnreadCount: (params?: {
    contextType?: string
    contextId?: string
  }) => Promise<any>
}

export const chatApi: ChatApi = {
  // 获取聊天消息列表
  getMessages: (params) => {
    return request.get('/chat/messages', { params })
  },
  
  // 发送消息（HTTP接口，主要用于历史消息同步）
  sendMessage: (data) => {
    return request.post('/chat/messages', data)
  },
  
  // 标记消息为已读
  markAsRead: (messageId) => {
    return request.put(`/chat/messages/${messageId}/read`)
  },
  
  // 标记所有消息为已读
  markAllAsRead: (data) => {
    return request.put('/chat/messages/read-all', data)
  },
  
  // 获取未读消息数量
  getUnreadCount: (params) => {
    return request.get('/chat/messages/unread-count', { params })
  }
}






